package com.mybatis.generator;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

/**
 * 
 * @ClassName: Generator
 * @Description:测试生成
 * @date 2015年8月11日 上午10:42:49
 */
public class Generator {

	@Test
	public void generator() throws Exception {
		try {

			boolean overwrite = true;

			InputStream stream = this.getClass()
					.getResource("/generatorConfig.xml").openStream();

			List<String> warnings = new ArrayList<String>();
			ConfigurationParser cp = new ConfigurationParser(warnings);
			Configuration config = cp.parseConfiguration(stream);
			DefaultShellCallback callback = new DefaultShellCallback(overwrite);
			MyBatisGenerator generator = new MyBatisGenerator(config, callback,
					warnings);
			generator.generate(null);
			System.out.println("映射文件已经生成");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
